<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>


    <footer th:fragment="table">
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">项目简介</div>
                            </div>
                            <div class="widget-body  am-fr">

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-4">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success"
                                                        onclick="insert()"><span class="am-icon-plus" data-toggle="modal" data-target="#myModal1"></span> 新增
                                                </button>
                                                <button type="button" class="am-btn am-btn-default am-btn-danger"
                                                        onclick="del()"><span class="am-icon-trash-o"></span> 删除
                                                </button>
                                                <!--<button type="button" class="am-btn am-btn-default am-btn-warning" onclick="insert()"><span class="am-icon-plus"></span> 导入</button>-->
                                                <button type="button" class="am-btn am-btn-default am-btn-secondary" onclick="derive()"><span class="am-icon-trash-o"></span> 导出</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}" id="riskstatus"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="房产抵押" th:selected="${riskstatus=='房产抵押'}">房产抵押</option>
                                            <option value="车辆抵押" th:selected="${riskstatus=='车辆抵押'}">车辆抵押</option>
                                            <option value="信用贷款" th:selected="${riskstatus=='信用贷款'}">信用贷款</option>
                                            <option value="零首付车贷" th:selected="${riskstatus=='零首付车贷'}">零首付车贷</option>
                                        </select>
                                        <select data-am-selected="{btnSize: 'sm'}" id="pagesize"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="5" th:selected="${pagesize==5}">5</option>
                                            <option value="10" th:selected="${pagesize==10}">10</option>
                                            <option value="10" th:selected="${pagesize==15}">15</option>
                                            <option value="10" th:selected="${pagesize==20}">20</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field" th:value="${#dates.format(predate,'yyyy-MM-dd')}" id="predate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field " th:value="${#dates.format(nextdate,'yyyy-MM-dd')}" id="nextdate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field " id="riskkeyword" th:value="${riskkeyword}">
                                        <span class="am-input-group-btn">
                                         <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
                                                 type="button" th:onclick="|page('${allrisk.pageNum}')|"></button>
                                    </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                    <div style="overflow-x:scroll">
                                        <table class="am-table am-table-compact am-table-striped tpl-table-black "
                                               id="example-r" style="width: 2000px">
                                            <thead>
                                            <tr>
                                                <th>
                                                    <button onclick="reSelectcre()"
                                                            class="am-btn  am-btn-default am-btn-success tpl-table-list-field"
                                                            type="button">反选
                                                    </button>
                                                </th>
                                                <th>编号</th>
                                                <th>项目名称</th>
                                                <th>项目总金额</th>
                                                <th>基本信息</th>
                                                <th>财政情况</th>
                                                <th>经营情况</th>
                                                <th>偿还能力</th>
                                                <th>实际控制人</th>
                                                <th>信息综合评分</th>
                                                <th>信用等级</th>
                                                <th>担保方</th>
                                                <th>抵押物信息</th>
                                                <th>担保机构信息</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr class="gradeX" th:each="risk,s : ${allrisk.list}">
                                                <td><input type="checkbox" name="persons" th:value="${risk.riskId}" class="choice"></td>
                                                <th th:text="${s.index}">编号</th>
                                                <th th:text="${risk.investName}">项目名称</th>
                                                <th th:text="${risk.investAmount}">项目总金额</th>
                                                <th th:text="${risk.riskBasename}">基本信息</th>
                                                <th th:text="${risk.riskCainame}">财政情况</th>
                                                <th th:text="${risk.riskJingname}">经营情况</th>
                                                <th th:text="${risk.riskChangname}">偿还能力</th>
                                                <th th:text="${risk.riskShiname}">实际控制人</th>
                                                <th th:text="${risk.riskPingname}">信息综合评分</th>
                                                <th th:text="${risk.riskDengname}">信用等级</th>
                                                <th th:text="${risk.riskDanname}">担保方</th>
                                                <th th:text="${risk.riskDiname}">抵押物信息</th>
                                                <th th:text="${risk.riskJigouname}">担保机构信息</th>
                                                <td>
                                                    <div class="tpl-table-black-operation">
                                                        <a href="javascript:;" data-toggle="modal" data-target="#myModal2" th:onclick="|findmost('${risk.investId}')|">更多信息</a>
                                                        <a href="javascript:;" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash" th:onclick="|delone('${risk.riskId}')|"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-u-lg-3">
                                            跳转至:<input type="number" id="num"  class="selectOption">/ 页
                                            <span>
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="findpage()"></button>
                                        </span>
                                        </div>

                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">
                                                <li ><a href="javascript:" th:onclick="|page('${allrisk.navigateFirstPage}')|">首页</a></li>
                                                <li  th:if="allrisk.hasPreviousPage"><a href="javascript:" th:onclick="|page('${allrisk.prePage}')|">«</a></li>


                                                <li th:each="pageNum:${#numbers.sequence(1,allrisk.pages)}">
                                                    <a th:text="${pageNum}" th:onclick="|page('${pageNum}')|"></a>
                                                </li>


                                                <li th:if="allrisk.hasNextPage"><a href="javascript:" th:onclick="|page('${allrisk.nextPage}')|">»</a></li>
                                                <li><a href="javascript:" th:onclick="|page('${allrisk.navigateLastPage}')|">尾页</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true" style="margin-top: 100px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel2">查看充值更多信息</h4>
                        </div>
                        <div style="text-align: center" id="comdetail">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>



            <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 100px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">增加项目</h4>
                        </div>
                        <div id="model">
                            <form>
                                请选择项目:
                                <select  id="insertInvest" >
                                    <option value="">请选择</option>
                                    <option th:value="${inve.investId}" th:text="${inve.investName}" th:each="inve : ${insertInvest}"></option>
                                </select><br />
                                基本信息:<input type="text" id="riskBasename"><br />
                                财政情况:<input type="text" id="riskCainame"><br/>
                                经营情况:<input type="text" id="riskJingname"><br/>
                                偿还能力:<input type="text" id="riskChangname"><br />
                                实际控制人:<input type="text" id="riskShiname"><br/>
                                信息综合评分:<input type="number" id="riskPingname"><br/>
                                信用等级:<input type="text" id="riskDengname"><br />
                                担保方:<input type="text" id="riskDanname"><br/>
                                抵押物信息:<input type="text" id="riskDiname"><br/>
                                担保机构信息:<input type="text" id="riskJigouname"><br/>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" th:onclick="subload()">提交</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
            <input type="hidden" id="allid" th:value="${ids}">
        </div>
    </footer>
    <script>


        function reSelectcre() {
            var allids=$('#allid').val().split(',')
            var allid=[]
            allid.push(parseInt(allids[0].split('')[1]))
            for(var i=1;i<allids.length;i++){
                allid.push(parseInt(allids[i]))
            }
            for(var i=0;i<risk.length;i++){
                for (var j=0;j<allid.length;j++){
                    if(allid[j]==risk[i]){
                        allid.splice(j,1)
                    }
                }
            }
            risk=allid
            alert(risk)
            $("input[name='persons']").each(function () {
                $(this).prop("checked",!$(this).prop("checked"))
            })
        }
        function page(i) {
            $.ajax({
                url:"/p2p/myrisk/getAllRisk",
                data:{
                    "riskstatus":$("#riskstatus").val(),
                    "predate":$("#predate").val(),
                    "nextdate":$("#nextdate").val(),
                    "riskkeyword":$("#riskkeyword").val(),
                    "pagenum":i,
                    "pagesize":$("#pagesize").val(),
                },
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        function findpage() {
            var pagesnum=$('#num').val();
            page(pagesnum);
        }

        $(".choice").click(function () {
            if($(this).prop("checked")){
                if(!($(this).val() in risk)){
                    risk.push($(this).val())
                }
            }else if(!$(this).prop("checked")){
                for (var i=0;i<risk.length;i++){
                    if(risk[i]===$(this).val()){
                        risk.splice(i,1);
                    }
                }
            }
        })

        //导出
        function derive() {
            var ides=risk;
            alert(ides);
            location.href="/p2p/myrisk/outRisk?id="+ides;
            risk=[];
        }

        //删除单个
        function delone(i) {
            $.ajax({
                url:"/p2p/myrisk/delonerisk",
                data:{
                    "id":i,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功")
                        page(1);
                    }else{
                        alert("删除失败!")
                    }
                }
            })
        }



        //批量删除
        function del() {
            var ides=risk;
            $.ajax({
                url:"/p2p/myrisk/delallrisk",
                data:{
                    "id":ides,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功");
                        page(1);
                        risk=[];
                    }else {
                        alert("删除失败!");
                    }
                }
            })
        }


        function findmost(i) {
            $.ajax({
                url: "/p2p/myrisk/getriskdetail",
                data:{"id":i},
                type: "get",
                dataType:"json",
                success:function (data) {
                    console.log(data)
                    var s="";
                    s+="<div class=\"modal-body\">\n" +
                        "项目编号<div>"+data.investNumber+"</div>\n" +
                        "项目名称<div>"+data.investName+"</div>\n" +
                        "项目起投金额<div>"+data.investStartpay+"</div>\n" +
                        "项目年化收益率<div>"+data.investGetyearmoney+"</div>\n" +
                        "用户投资期限<div>"+data.investDay+"</div>\n" +
                        "公司投资总金额<div>"+data.investAmount+"</div>\n" +
                        "项目期限<div>"+data.investDeadline+"</div>\n" +
                        "项目起投时间<div>"+data.investReleasetime+"</div>\n" +
                        "项目支付时间<div>"+data.investPaytime+"</div>\n" +
                        "项目保障级别<div>"+data.investStafguard+"</div>\n" +
                        "项目投资余额<div>"+data.investBalance+"</div>\n" +
                        "项目投资进度<div>"+data.investSubsribe+"</div>\n" +
                        "项目期限剩余天数<div>"+data.investRemaindertime+"</div>\n" +
                        "项目每万元收益<div>"+data.investGetmonofyear+"</div>\n" +
                        "\n" +
                        "</div>"
                    $('#comdetail').html(s)
                },
            })
        }


        //增加
        function subload() {
            $.ajax({
                url:"/p2p/myrisk/insertRisk",
                data:{
                    "riskBasename":$("#riskBasename").val(),
                    "riskCainame":$("#riskCainame").val(),
                    "riskJingname":$("#riskJingname").val(),
                    "riskChangname":$("#riskChangname").val(),
                    "riskShiname":$("#riskShiname").val(),
                    "riskPingname":$("#riskPingname").val(),
                    "riskDengname":$("#riskDengname").val(),
                    "riskDanname":$("#riskDanname").val(),
                    "riskDiname":$("#riskDiname").val(),
                    "riskJigouname":$("#riskJigouname").val(),
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜添加成功!");
                        page(1);
                    }else{
                        alert("抱歉,添加失败!");
                    }
                }
            })
        }



    </script>
</head>
</html>
